package com.mls.fivedistrict.controller.backend;


import com.github.pagehelper.PageInfo;
import com.mls.fivedistrict.common.PageFilter;
import com.mls.fivedistrict.common.RequestHolder;
import com.mls.fivedistrict.common.ServiceResponse;
import com.mls.fivedistrict.pojo.VoteOption;
import com.mls.fivedistrict.pojo.VoteOptionPayIntegral;
import com.mls.fivedistrict.server.VoteOptionPayIntegralService;
import com.mls.fivedistrict.server.VoteOptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 投票选项支付方式 前端控制器
 * </p>
 *
 * @author Five Team
 * @since 2018-05-21
 */
@RestController
@RequestMapping("/voteOptionPayIntegral")
public class VoteOptionPayIntegralController {
    @Autowired
    private VoteOptionPayIntegralService voteOptionPayIntegralService;

    @RequestMapping("/v1/voteOptionPayIntegrals")
    public ServiceResponse getList() {
        PageFilter pageFilter = RequestHolder.getPageFilter();
        List<VoteOptionPayIntegral> voteOptionPayIntegralList = voteOptionPayIntegralService.selectList(pageFilter.getWrapper());
        PageInfo pageInfo = new PageInfo(voteOptionPayIntegralList);
        return ServiceResponse.createSuccessResponse(pageInfo);
    }


    @GetMapping("/v1/voteOptionPayIntegral/{voteOptionPayIntegrals}")
    public ServiceResponse getVoteOption(@PathVariable("voteOptionPayIntegrals") Long voteOptionPayIntegralId) {
        VoteOptionPayIntegral voteOptionPayIntegral = voteOptionPayIntegralService.selectById(voteOptionPayIntegralId);
        return ServiceResponse.createSuccessResponse(voteOptionPayIntegral);
    }


    @PostMapping("/v1/voteOptionPayIntegral")
    public ServiceResponse insert(@RequestBody VoteOptionPayIntegral voteOptionPayIntegral) {
        boolean insert = voteOptionPayIntegralService.insert(voteOptionPayIntegral);
        if (!insert) {
            return ServiceResponse.createErrorResponse("插入失败");
        }
        return ServiceResponse.createSuccessResponse("插入成功");
    }

    @PutMapping("/v1/voteOptionPayIntegral/{voteOptionPayIntegralId}")
    public ServiceResponse update(@PathVariable("voteOptionPayIntegralId") Long voteOptionPayIntegralId, @RequestBody VoteOptionPayIntegral voteOptionPayIntegral) {
        voteOptionPayIntegral.setId(voteOptionPayIntegralId);
        boolean update = voteOptionPayIntegralService.updateById(voteOptionPayIntegral);
        if (!update) {
            return ServiceResponse.createErrorResponse("修改失败");
        }
        return ServiceResponse.createSuccessResponse("修改成功");
    }

    @DeleteMapping("/v1/voteOptionPayIntegral/{voteOptionPayIntegralId}")
    public ServiceResponse delete(@PathVariable("voteOptionPayIntegralId") Long voteOptionPayIntegralId) {
        VoteOptionPayIntegral voteOptionPayIntegral = new VoteOptionPayIntegral();
        voteOptionPayIntegral.setId(voteOptionPayIntegralId);
        voteOptionPayIntegral.setIsDelete(false);
        boolean delete = voteOptionPayIntegralService.updateById(voteOptionPayIntegral);
        if (!delete) {
            return ServiceResponse.createErrorResponse("删除失败");
        }
        return ServiceResponse.createSuccessResponse("删除成功");
    }
}

